﻿<?php 
defined('_JEXEC') or die('Restricted access'); 
 
jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

if($this->data->name != '')
	$this->data->name = unserialize($this->data->name);

if($this->data->des != '')
	$this->data->des = unserialize($this->data->des);

?>
  <style>
	#backgroundfile{
		width:160px;
		text-align: center;
	}
	
	#imagefile{
		text-align:left;
	}
	
	.image_prview {
	    background-color: #F5F5F5;
	    border: 2px solid #E5E5E5;
	    float: left;
	    margin: 2px;
	    padding: 5px;
	    text-align: center;
	    width: 160px;
	}
</style>
<link href="<?php echo JURI::base(true)?>/components/com_wrd/assets/css/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/swfobject.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery.uploadify.v2.1.4.min.js"></script>

<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery('#image_upload').uploadify({
		    'uploader'  	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/flash/uploadify.swf',
		    'script'    	: '<?php echo JURI::base(true)?>/components/com_wrd/classes/fileUploader.php',
		    'cancelImg' 	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/images/cancel.png',
		    'folder'    	: '<?php echo str_ireplace('administrator', '', JURI::base(true)).'wrd' ?>',
		    'fileExt'		: '*.jpg;*.png',
	    	'fileDesc'		: 'Web Image Files (.JPG , .PNG)',
		    'auto'      	: false,
		    'multi'     	: true,
		    'queueID'    	: 'custom-queue',
		    'queueSizeLimit' : 10,
		    'simUploadLimit' : 2,
		    'scriptData'  	: {'typeupload':'image','userid':<?php echo $this->user->id ?>},
		    'onComplete'  	: function(event, ID, fileObj, response, data) {
		    	obj = jQuery.parseJSON(response);
	        	jQuery('#imagefile').append('<div id="image_'+obj.fileid+'" class="image_prview"><div><a class="modal" href="<?php echo JURI::base(true).'/../wrd/image/'?>'+obj.filename+'"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'?>'+obj.filename+'" /></a><div><a onclick="remove_image('+obj.fileid+')" href="javascript:void(null)">Remove</a></div><div>');
			}
		});

		jQuery('#image1_upload').uploadify({
		    'uploader'  	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/flash/uploadify.swf',
		    'script'    	: '<?php echo JURI::base(true)?>/components/com_wrd/classes/fileUploader.php',
		    'cancelImg' 	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/images/cancel.png',
		    'folder'    	: '<?php echo str_ireplace('administrator', '', JURI::base(true)).'wrd' ?>',
		    'fileExt'		: '*.jpg;*.png',
	    	'fileDesc'		: 'Web Image Files (.JPG , .PNG)',
		    'auto'      	: true,
		    'scriptData'  	: {'typeupload':'image1','userid':<?php echo $this->user->id ?>},
		    'onComplete'  	: function(event, ID, fileObj, response, data) {
		    	obj = jQuery.parseJSON(response);
	        	jQuery('#imagefile1').append('<div id="image_'+obj.fileid+'" class="image_prview"><div><a class="modal" href="<?php echo JURI::base(true).'/../wrd/image/'?>'+obj.filename+'"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'?>'+obj.filename+'" /></a><div><a onclick="remove_image('+obj.fileid+')" href="javascript:void(null)">Remove</a></div><div>');
			}
		});

		jQuery('#image2_upload').uploadify({
		    'uploader'  	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/flash/uploadify.swf',
		    'script'    	: '<?php echo JURI::base(true)?>/components/com_wrd/classes/fileUploader.php',
		    'cancelImg' 	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/images/cancel.png',
		    'folder'    	: '<?php echo str_ireplace('administrator', '', JURI::base(true)).'wrd' ?>',
		    'fileExt'		: '*.jpg;*.png',
	    	'fileDesc'		: 'Web Image Files (.JPG , .PNG)',
		    'auto'      	: true,
		    'scriptData'  	: {'typeupload':'image2','userid':<?php echo $this->user->id ?>},
		    'onComplete'  	: function(event, ID, fileObj, response, data) {
		    	obj = jQuery.parseJSON(response);
	        	jQuery('#imagefile2').append('<div id="image_'+obj.fileid+'" class="image_prview"><div><a class="modal" href="<?php echo JURI::base(true).'/../wrd/image/'?>'+obj.filename+'"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'?>'+obj.filename+'" /></a><div><a onclick="remove_image('+obj.fileid+')" href="javascript:void(null)">Remove</a></div><div>');
			}
		});
		
		jQuery('#fasttrack').click(function(){

			var n = $(this).attr('checked') ? 1 : 0 ;
			if(n == 1){
				jQuery('.ex_nomal').hide();
				jQuery('.ex_cash').show();
			}
			else{
				jQuery('.ex_nomal').show();
				jQuery('.ex_cash').hide();
			}
		});
	});
	
	function remove_image(id){
		jQuery.ajax({
			url: "index.php?option=com_wrd&task=removefile",
			type: "POST",
			data: 'id='+id,
			success: function (res) {
				jQuery('#image_'+id).remove();
			}
		});
	}
	
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save') {
			if (document.adminForm.name.value == "") {
				alert( 'Must have Products name !' );
				document.adminForm.name.focus();
				return false;
			}
			if (document.adminForm.point.value == "") {
				alert( 'Must have point !' );
				document.adminForm.point.focus();
				return false;
			}
			if (isNaN(document.adminForm.point.value)) {
				alert( 'Point must have a number !' );
				document.adminForm.point.focus();
				return false;
		    }
			if (document.adminForm.quantity.value == "") {
				alert( 'Must have Quantity !' );
				document.adminForm.quantity.focus();
				return false;
			}
			if (isNaN(document.adminForm.quantity.value)) {
				alert( 'Quantity must have a number !' );
				document.adminForm.quantity.focus();
				return false;
		    }
			if (document.adminForm.cat_id.value == 0) {
				alert( 'Please select a category !' );
				document.adminForm.cat_id.focus();
				return false;
			}


			if(parseInt(document.adminForm.point.value) == 0 && parseInt(document.adminForm.pointx.value) == 0 && parseInt(document.adminForm.cash.value) == 0){
				alert( 'Please check point' );
				document.adminForm.point.focus();
				return false;
			}
			submitform( pressbutton );
		}
	}
</script>

<form  id="adminForm" action="<?php echo JRoute::_ ( "index.php?option=com_wrd&controller=products" )?>" method="post" name="adminForm">
	<div class="row-fluid">
	<fieldset class="adminform">
	<legend>
	<?php echo JText::_ ( 'Details' )?></legend>
	<table class="table table-striped adminlist">
		<?php foreach ($this->current_languages as $lang):?>
		<tr>
			<td class="key"><label for="title"><?php
			echo JText::_ ( 'Product Name' ).' '.$lang->name?>:</label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->name[$lang->language]; ?>" id="name" name="name_<?php echo $lang->language; ?>" class="name" /> *
			</td>
		</tr>
		<?php endforeach; ?>
		<tr>
			<td class="key"><label for="title">Product Code:</label></td>
			<td colspan="4">
				<input type="text" title="Product Code" value="<?php echo $this->data->p_code; ?>" id="p_code" name="p_code" class="p_code" />
			</td>
		</tr>
		<tr>
			<td class="key"><label title="Nếu check sẽ là Voucher" for="title">Voucher</label></td>
			<td colspan="4">
				<input type="checkbox" <?php if($this->data->voucher) echo "checked"; ?> title="Voucher"  id="voucher" name="voucher" class="voucher" />
			</td>
		</tr>
		<tr>
			<td class="key"><label for="title">Fash Track:</label></td>
			<td colspan="4">
				<input type="checkbox" title="fast track"  id="fasttrack" name="fasttrack" class="fasttrack" />
			</td>
		</tr>
		<tr class="ex_nomal">
			<td class="key"><label for="title"><?php echo JText::_ ( 'Point' )?>:</label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->point; ?>" id="point" name="point" class="point" />
			</td>
		</tr>
		<tr class="ex_cash" style="display: none;">
			<td class="key"><label for="title"><?php echo JText::_ ( 'Point' )?>:</label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->pointx; ?>" id="pointx" name="pointx" class="pointx" />
			</td>
		</tr>
		
		<tr class="ex_cash" style="display: none;">
			<td class="key"><label for="title"><?php echo JText::_ ( 'Cash' )?>:</label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->cash; ?>" id="cash" name="cash" class="cash" /> *
			</td>
		</tr>
		
		<tr>
			<td class="key"><label for="title"><?php echo JText::_ ( 'Price: ' )?></label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->price; ?>" id="price" name="price" class="price" /> 
			</td>
		</tr>
		<tr>
			<td class="key"><label title ="Giá tiền thực của sản phẩm" for="title">Cost Pricing : </label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->cost_pricing; ?>" id="cost_pricing" name="cost_pricing" class="cost_pricing" /> 
			</td>
		</tr>
		<tr>
			<td class="key"><label for="title"><?php echo JText::_ ( 'Quantity' )?>:</label></td>
			<td colspan="2">
				<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->quantity; ?>" id="quantity" name="quantity" class="quantity" /> *
			</td>
		</tr>
		
		<tr>
			<td class="key"><label for="title"><?php echo JText::_ ( 'Category' )?>:</label></td>
			<td colspan="2">
				<?php echo $this->parent; ?>
			</td>
		</tr>
		<tr>
			<td class="key"><label for="title"><?php
			echo JText::_ ( 'Publish up' )?>:</label></td>
			<td colspan="2">
				<?php
					echo JHTML::_ ( 'calendar', ($this->data->published_up != '') ? $this->data->published_up : '', 'published_up', 'published_up', '%Y-%m-%d');
				?>
			</td>
		</tr>
		<tr>
			<td class="key"><label for="title"><?php
			echo JText::_ ( 'Publish down' )?>:</label></td>
			<td colspan="2">
				 <?php
					echo JHTML::_ ( 'calendar', ($this->data->published_down != '') ? $this->data->published_down : '', 'published_down', 'published_down', '%Y-%m-%d');
					?>
			</td>
		</tr>
		<tr>
			<td class="key"><label for="title"><?php
			echo JText::_ ( 'Publish' )?>:</label></td>
			<td colspan="2">
				<?php
				echo $this->lists ['published'];
				?>
			</td>
		</tr>
		
		<?php foreach ($this->current_languages as $lang):?>
		<tr>
			<td class="key"><label for="title"><?php
			echo JText::_ ( 'Description' ).' '.$lang->name; ?>:</label></td>
			<td colspan="2">
				<?php
				echo $this->wysiwyg->display('des_'.$lang->language, htmlspecialchars($this->data->des[$lang->language], ENT_COMPAT, 'UTF-8'),  '100%', '200', '40', '5',true);
				?>
			</td>
		</tr>
		<?php endforeach; ?>
	</table>
	<input type="hidden" name="created_id" value="<?php echo $this->user->id;?>" /> 
	<input type="hidden" name="controller" value="products" /> 
	<input type="hidden" name="option" value="com_wrd" /> 
	<input type="hidden" name="id" value="<?php echo ( int ) $this->data->id; ?>" /> 
	<input type="hidden" name="task" value="" />
	<?php
		echo JHTML::_ ( 'form.token' );
	?>
	</fieldset>
</div>
</form>
<div class="row-fluid">
		<fieldset class="panelform">
			<legend>Image1 Upload (245 x 246)</legend>
			<input id="image1_upload" name="image1_upload" type="file" />
			
			
			<div id="imagefile1">
				<?php if(!empty($this->filesalbum1)):?>
					<?php foreach ($this->filesalbum1 as $file): ?>
						<?php if($file->type == 'image1'): ?>
							<div id="image_<?php echo $file->id; ?>" class="image_prview">
								<div><a class="modal" href="<?php echo JURI::base(true).'/../wrd/image1/'.$file->name?>"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'.$file->name?>" /></a></div>
								<div><a onclick="remove_image('<?php echo $file->id; ?>')" href="javascript:void(null)">Remove</a></div>
							</div>
						<?php endif;?>
					<?php endforeach; ?>
				<?php endif;?>
			</div>
		</fieldset>
		
		<fieldset class="panelform">
			<legend>Image2 Upload (247 x 108)</legend>
			<input id="image2_upload" name="image1_upload" type="file" />
			
			
			<div id="imagefile2">
				<?php if(!empty($this->filesalbum2)):?>
					<?php foreach ($this->filesalbum2 as $file): ?>
						<?php if($file->type == 'image2'): ?>
							<div id="image_<?php echo $file->id; ?>" class="image_prview">
								<div><a class="modal" href="<?php echo JURI::base(true).'/../wrd/image2/'.$file->name?>"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'.$file->name?>" /></a></div>
								<div><a onclick="remove_image('<?php echo $file->id; ?>')" href="javascript:void(null)">Remove</a></div>
							</div>
						<?php endif;?>
					<?php endforeach; ?>
				<?php endif;?>
			</div>
		</fieldset>
		
		<fieldset class="panelform">
			<legend>Gallery Upload (265 x 329)</legend>
			<input id="image_upload" name="audio_upload" type="file" />
			<div id="custom-queue" class="uploadifyQueue"></div>
			<a href="javascript:jQuery('#image_upload').uploadifyUpload();">Upload Files</a>
			<div id="imagefile">
				<?php if(!empty($this->filesalbum)):?>
					<?php foreach ($this->filesalbum as $file): ?>
						<?php if($file->type == 'image'): ?>
							<div id="image_<?php echo $file->id; ?>" class="image_prview">
								<div><a class="modal" href="<?php echo JURI::base(true).'/../wrd/image/'.$file->name?>"><img src="<?php echo JURI::base(true).'/../wrd/thumb/'.$file->name?>" /></a></div>
								<div><a onclick="remove_image('<?php echo $file->id; ?>')" href="javascript:void(null)">Remove</a></div>
							</div>
						<?php endif;?>
					<?php endforeach; ?>
				<?php endif;?>
			</div>
		</fieldset>
</div>